package com.syaccp.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.syaccp.model.SysDictType;
import com.syaccp.mapper.SysDictTypeMapper;
import com.syaccp.request.DictTypeDTO;
import com.syaccp.service.DictTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author lixin
 * @since 2023-07-02
 */
@Service("dictTypeService")
public class DictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements DictTypeService {
    @Override
    public PageInfo<SysDictType> queryPage(DictTypeDTO queryDTO) {
        PageHelper.startPage(queryDTO.getPageIndex(),queryDTO.getPageSize());
        QueryWrapper<SysDictType>queryWrapper=new QueryWrapper<>();
        if (!StringUtils.isEmpty(queryDTO.getName())){
            queryWrapper.like("name",queryDTO.getName());
        }
        PageInfo<SysDictType> pageInfo = new PageInfo<>(this.baseMapper.selectList(queryWrapper));


    /*QueryWrapper<SysDictData>wrapper=new QueryWrapper<>();
    List<SysDictData> sysDictData=null;
    for (SysDictType sysDictType : pageInfo.getList()) {
        wrapper.eq("type",sysDictType.getType());
        sysDictType.setChildren(sysDictDataMapper.selectList(wrapper));
        wrapper.clear();
    }*/
        return pageInfo;
    }

    @Override
    public void saveAndUpdate(SysDictType sysDictType) {
        if (sysDictType.getId()>0){
            //更新
            this.updateById(sysDictType);
        }else {
            //添加
            this.save(sysDictType);
        }
    }
}
